import axios from "axios";
import {
	Message
} from 'view-design';
import common from "./common.js";
import store from '../store'
const service = axios.create({
	// withCredentials: true,
	baseURL: common.BASE_URL, // api的base_url
	timeout: 180000, // 请求超时时间2
	headers: {

	}
})

service.interceptors.response.use(response, error)
service.interceptors.request.use(request, error)




function response(res) {
	var result = res.data
	if (result.code == 200) {
		return result;
	} else {
		Message['warning']({
			background: true,
			content: result.msg
		});
	}
}

function request(config) {
	if (store.getters.isAuthenticated) {
		// let each request carry token
		// ['X-Token'] is a custom headers key
		// please modify it according to the actual situation
		config.headers['X-Token'] = store.getters.isAuthenticated
		config.headers.common['Authorization'] = "Bearer " + store.getters.isAuthenticated;

	}
	return config

}

function error(error) {
	return Promise.reject(error)
}


export default service
